package cn.zzszxyy.hr.repository;

import cn.zzszxyy.hr.model.EmployeeEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 作者:张伟
 * <p>
 * 联系:adamzzww@163.com
 * 时间:2016-11-28
 * 说明:无
 */
@Repository
public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Integer>, JpaSpecificationExecutor<EmployeeEntity> {

    @Transactional
    @Modifying
    @Query("update EmployeeEntity e set e.curDept=?1 where e.employeeId = ?2")
    void updateCurDeptById(int curDept, int employeeId);

    @Query(value = "select e from EmployeeEntity e where e.employeeName like %?1",
            countQuery = "select count(e) from EmployeeEntity e where e.employeeName like %?1")
    Page<EmployeeEntity> findByEmployeeNameLike(String employeeName, Pageable pageable);

}
